package com.mallcai.bigdata.ladon.controller.system.form;

import com.mallcai.bigdata.ladon.dpl.entity.system.User;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import javax.validation.constraints.NotBlank;

/**
 * Created by oneape<oneape15@163.com>
 * Created 2019-07-03 11:49.
 * Modify:
 */
@Data
public class RegForm {
    @NotBlank(message = "登录名不能为空", groups = {RegCheck.class})
    private String username;  // 登录名
    @NotBlank(message = "用户名称不能为空", groups = {RegCheck.class})
    private String nickname;  // 用户名称
    @NotBlank(message = "登录密码不能为空", groups = {RegCheck.class})
    private String password;  // 登录密码
    @NotBlank(message = "所在部门不能为空", groups = {RegCheck.class})
    private String department;// 所在部门
    @NotBlank(message = "邮箱地址不能为空", groups = {RegCheck.class})
    private String email;
    @NotBlank(message = "电话号码不能为空", groups = {RegCheck.class})
    private String phone;


    public interface RegCheck {
    }

    public User toEntity() {
        User u = new User();
        u.setNickname(StringUtils.trim(nickname));
        u.setUsername(StringUtils.trim(username));
        u.setEmail(StringUtils.trim(email));
        u.setPhone(StringUtils.trim(phone));
        u.setPassword(StringUtils.trim(password));
        u.setDepartment(department);
        return u;
    }
}
